# -*- coding: utf-8 -*-
# @Time    : 2021/3/19 17:34
# @Author  : Zhangrenjie
# @Email   : zhangrenjie1998@163.com
# @File    : text_guess.py
# @Software: PyCharm
import random

# 数据生成一个数
rand_num = random.randint(1, 100)
print(rand_num)
for i in range(1, 4):
    # 判断输入数值进行异常抛出
    while True:
        try:
            root_input = int(input("请输入一个数字: "))
            break
        except ValueError:
            print("您输入的不是数字，请再次尝试输入！")
    count = i
    if root_input > rand_num:
        # if i != 3:
        #     print(f"您猜大了！\n请重新输入\t您还有{4-1-i}次机会")
        #     count = i
        # else:
        #     print("您猜大了，您的机会已用完！")
        #     count = i
        print("您猜大了，您的机会已用完！") if i ==3 else print(f"您猜大了！\n请重新输入\t您还有{4-1-i}次机会")
        # count = i
    elif root_input < rand_num:
        if i != 3:
            print(f"您猜小了！\n请重新输入\t您还有{4-1-i}次机会")
            # count = i
        else:
            print("您猜小了，您的机会已用完！")
            # count = i
    else:
        print("恭喜您，猜中了！")
        # count = i
        break
print(f"{'='*50}\n最终数字是：{rand_num}\n您一共猜了{i}次")